/*
 * Copyright (c) 2018-2999 北京小象智慧信息科技有限公司 All rights reserved.
 *
 * https://www.xiaoxiangai.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.BannerImage;
import com.yami.shop.bean.model.IndexImg;
import com.yami.shop.bean.model.Product;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.util.SecurityUtils;
import com.yami.shop.service.BannerImageService;
import com.yami.shop.service.IndexImgService;
import com.yami.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;
import java.util.Objects;

/**
 * @author lgh on 2018/11/26.
 */
@RestController
@RequestMapping("/admin/bannerImage")
public class BannerImageController {

    @Autowired
    private BannerImageService bannerImageService;

    @Autowired
    private ProductService productService;


    /**
     * 分页获取
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<BannerImage>> page(BannerImage bannerImage, PageParam<BannerImage> page) {
        IPage<BannerImage> bannerImageIPage = bannerImageService.page(page,
                new LambdaQueryWrapper<BannerImage>());
        return ResponseEntity.ok(bannerImageIPage);
    }

    /**
     * 获取信息
     */
    @GetMapping("/info")
    public ResponseEntity<BannerImage> info(Long bannerId) {
       BannerImage bannerImage = bannerImageService.getById(bannerId);
        return ResponseEntity.ok(bannerImage);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@PreAuthorize("@pms.hasPermission('admin:bannerImage:save')")
    public ResponseEntity<Void> save(@RequestBody @Valid BannerImage bannerImage) {
        bannerImage.setCreateTime(new Date());
        bannerImageService.save(bannerImage);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public ResponseEntity<Void> update(@RequestBody BannerImage bannerImage) {
        bannerImageService.saveOrUpdate(bannerImage);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public ResponseEntity<Void> delete(@RequestBody Long[] ids) {
        bannerImageService.deleteBannerIds(ids);
        return ResponseEntity.ok().build();
    }
}
